﻿[#include "/app/common/layout/__frontmainlayout.html"/]

[#assign pageCss]
<link rel="stylesheet" href="${ContextPath}/admin/assets/css/signin.css" />
[/#assign]

[#assign pageJavascript]
<script type="text/javascript">
function select1() {
	$.ajax(
    {
    	type: "post",
    	url: "${ContextPath}/report/handler",
    	data: { "type": "type" },
        success: function (msg) {
        	$("#selectType").append("<option value='-1'>请选择故障大类</option>");
        	for (var i = 0; i < msg.typeList.length; i++) {
            	$("#selectType").append("<option value=" + msg.typeList[i].id + ">" + msg.typeList[i].name + "</option>");
        	}
            select2();
        }
	})
};
function select2() {
	$("#selectApartment").html("");
	$("#selectChildType").html("");
	$.ajax(
	{
		type: "post",
		url: "${ContextPath}/report/handler",
		data: { "type": "apartment","typeid":$('#selectType').val() },
		success: function (msg) {
			$("#selectApartment").append("<option value='-1'>请选择运维部门</option>");
			$("#selectChildType").append("<option value='-1'>请选择故障小类</option>");
			for (var i = 0; i < msg.apartmentList.length; i++) {
				if(msg.apartmentList[i].id==2){
					$("#selectApartment").append("<option value=" + msg.apartmentList[i].id + ">" +msg.apartmentList[i].name + "</option>");
				}
			}
			
			for (var i = 0; i < msg.childTypeList.length; i++) {
				$("#selectChildType").append("<option value=" + msg.childTypeList[i].id + ">" +msg.childTypeList[i].name + "</option>");
			}
			select3();
		}
	})
};

function select3() {
	$("#selectChildApartment").html("");
	$.ajax(
	{
		type: "post",
		url: "${ContextPath}/report/handler",
		data: { "type": "childApartment","childTypeid":$('#selectChildType').val(),"rootApartment": $('#selectApartment').val()},
		success: function (msg) {
			$("#selectChildApartment").append("<option value='-1'>请选择运维组别</option>");
			for (var i = 0; i < msg.childApartmentList.length; i++) {
				$("#selectChildApartment").append("<option value=" + msg.childApartmentList[i].id + ">" +msg.childApartmentList[i].name + "</option>");
			}
		}
	})
};
function select4() {
	$("#selectChildApartment").html("");
	var apartmentArray=new Array();
	$("#selectApartment option:selected").each(function(i){ 
			apartmentArray[i]=$(this).val(); 
	});
	if(apartmentArray.length>1){
		$('#childdiv').hide();
	}
	if(apartmentArray.length<=1){
		$('#childdiv').show();
	}
	$.ajax(
	{
		type: "post",
		url: "${ContextPath}/report/handler",
		data: { "type": "childApartment","childTypeid":$('#selectChildType').val(),"rootApartment": $('#selectApartment').val()},
		success: function (msg) {
			$("#selectChildApartment").append("<option value='-1'>请选择运维组别</option>");
			for (var i = 0; i < msg.childApartmentList.length; i++) {
				$("#selectChildApartment").append("<option value=" + msg.childApartmentList[i].id + ">" +msg.childApartmentList[i].name + "</option>");
			}
		}
	})
};

function select5(){
	$.ajax(
	{
		type: "post",
		url: "${ContextPath}/report/handler",
		data: { "type": "effective","apartmentid":$('#selectChildApartment').val() },
		success: function (msg) {
			if(msg.state=="error"){
				alertModal("该分组无运维人员，请选择其他运维组!");
				$('#alertModal').modal();
				select3();
			}
		}
	})
}


$(function(){
	select1();
	$('#selectType').bind("change", select2);
	$('#selectChildType').bind("change", select3);
	$('#selectApartment').bind("change", select4);
	$('#selectChildApartment').bind("change", select5);
});

function alertModal(msg){
	$("#modal-title-content").html("提示!");  
	$("#modal-body-content").html(msg);  
}

$(document).ready(function(){
	$("#reportsave").click(function(){
		
		$.ajax({
			type:"post",
			url:"${ContextPath}/report/save",
			data:{
					"selectType":$('#selectType').val(),
					"childTypeid":$('#selectChildType').val(),
					"selectApartment":$('#selectApartment').val(),
					"selectChildApartment":$('#selectChildApartment').val(),
					
					"order.offer_user":$('#userid').val(),
					"order.title":$('#title').val(),
					"order.description":$('#description').val(),
					"order.type":$('#selectChildType').val(),
					"order.level":$('#selectLevel').val(),
					
			},
			success:function(msg){
				alertModal(msg.state);
				$('#alertModal').modal();
				$('#alertModal').on('hidden.bs.modal', function () {
					if(msg.state=='提交成功！'){
						window.location.href='${ContextPath}/report/reports'
					}
				});
			}
		});
	});

});


</script>

[/#assign]

[@mainlayout pageJavascript=pageJavascript pageCss=pageCss currentMenu="offerFlag"]
<div class="index-background">
	
	<form class="form-horizontal" role="form"  action="${ContextPath}/report/save" method="post" >
		[#include "_formadd.html" /]
	</form>
</div>
[/@mainlayout]